package com.freewater.springboot.demo.ioc.lookupmethodinject.java8function;

import com.freewater.springboot.demo.ioc.lookupmethodinject.AsyncCommand;
import com.freewater.springboot.demo.ioc.lookupmethodinject.Command;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import java.util.function.Function;

@Configuration
@ComponentScan(basePackages = "com.freewater.springboot.demo.lookupmethodinject.java8function")
public class AppConfiguration {

    @Bean
    public Function<String, Command> commandFunction() {
        return (name) -> asyncCommand();
    }

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public AsyncCommand asyncCommand() {
        return new AsyncCommand();
    }

    @Bean
    public CommandManager commandManager() {
        return new CommandManager();
    }
}
